package com.wgchao.identityrightsmanagement.domain.organization.model;


import com.wgchao.identityrightsmanagement.infrastructure.exception.ObjectNotMatchException;

/**
 * @ClassName: AssignOfficeToAccountService
 * @author: wgchao
 * @createTime: 2020/6/17 9:15 AM
 * @Description: 为账户分配职位
 */
public class AssignOfficesToAccountService {
    private String identify;
    private Account account;
    private Department department;
    private Office office;
    private DepartmentOffice departmentOffice;
    public AssignOfficesToAccountService(String identify, Account account, Department department, Office office,
                                         DepartmentOffice departmentOffice) {
        this.identify = identify;
        this.account = account;
        this.department = department;
        this.office = office;
        this.departmentOffice = departmentOffice;
    }

    public AccountOffice assignOfficesToAccount(){
        this.account.normalException();
        this.department.normalException();
        this.office.normalException();
        if(!this.departmentOffice.getDepartmentCode().equals(account.getDepartmentCode())){
            throw new ObjectNotMatchException(this.office.getName()+"职位不在账户所在部门,不可分配");
        }
        AccountOffice accountOffice = new AccountOffice(this.identify, this.account.getUsername(), department.getCode(),
                this.departmentOffice.getOfficeCode());
        return accountOffice;
    }
}
